﻿$(document).ready(function () {

    $("#res1").hide();
    $("#res2").hide();
    $("#res3").hide();
    $("#info").hide();
    $("#restaurantList").hide();

    $(".shoppingCartButton").click(OnAddToShoppingCart);


    $("#findRestaurant").click(onFindRestaurantClick);
    $(".list-group-item").click(onRestaurantClick);

    $("#res1 list-group-item").click(onFoodClick);
    $("#res2 list-group-item").click(onFoodClick);
    $("#res3 list-group-item").click(onFoodClick);
    $("#sendOrder").click(sendOrder);
});

var sum = 0;

function OnAddToShoppingCart(args) {
    var element = $(args.currentTarget.parentNode.parentNode);
    var data = element[0].innerText.split('\n');

    var id = element.attr("id");
    var name = data[0];
    var description = data[1];
    var price = parseFloat(data[2].split(' '));

    sum = price + sum;
    $("#priceSum").text(sum + " zł");
    console.log(sum);
    var currentOrderTable = $("#currentOrder").find('tbody');

}

var address;

function onFindRestaurantClick() {
    $("#main").hide(1500);
    address = $("#address").val();
    $("#restaurantList").show(1500);
}

function onRestaurantClick(eventArgs) {
    $("#restaurantList").hide(1500);
    console.log(eventArgs);

    var nr = eventArgs.toElement.parentElement.innerText.split('.')[0];
    $("#res1").show(1500);

}

function onFoodClick(eventArgs) {

}

function sendOrder()
{
    $("#res1").hide(1500);
    $("#info").show(1500);
}